package com.example.huichaoliu;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

import com.huichaoliu.app.R;
import com.rederxu.farmer.BaseActivity;
import com.rederxu.tools.DisplayUtils;

public class DesignerListActivity extends BaseActivity implements OnClickListener,OnItemClickListener {

	private GridView gridView = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_designer_list);
		super.onCreate(savedInstanceState);
	}

	@Override
	public void onClick(View v) {
		switch(v.getId()){
		case R.id.left_button:
			finish();
			break;
		}
	}

	@Override
	public void init() {
		findViewById(R.id.left_button).setOnClickListener(this);
		
		gridView = (GridView) findViewById(R.id.gridView);
		gridView.setOnItemClickListener(this);
	}

	@SuppressLint("NewApi") @Override
	public void initData() {
		int width = (DisplayUtils.getScreenWidth(this) - DisplayUtils.dipToPx(this, 24) - gridView.getHorizontalSpacing() * 2) / 3;
		gridView.setAdapter(new Adapter(width));
	}

	@Override
	public void onNetworkChanged(boolean isMobNetConnected,
			boolean isWifiConnected) {
		// TODO Auto-generated method stub

	}

	private class Adapter extends BaseAdapter{

		private int width = 0;
		
		public Adapter(int width) {
			this.width = width;
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return 10;
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			if(convertView == null){
				convertView = LayoutInflater.from(mContext).inflate(R.layout.item_designer_list, null);
				ImageView ic_avatar = (ImageView) convertView.findViewById(R.id.ic_avatar);
				android.widget.LinearLayout.LayoutParams lp = new android.widget.LinearLayout.LayoutParams(width, width);
				ic_avatar.setLayoutParams(lp);
			}
			return convertView;
		}
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		startActivity(new Intent(this,DesignerDetailActivity.class));
	}
}
